package com.kingint.web.portal.serve.controller;
import com.kingint.common.unitedresult.K;
import com.kingint.mbg.sys.entity.Notice;
import com.kingint.mbg.sys.entity.UmsMember;
import com.kingint.web.sys.service.NoticeService;
import com.kingint.web.sys.service.NoticeUserService;
import com.kingint.web.sys.service.UmsAdminService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @描述：控制类
 * @作者: wxh
 * @日期: 2020-12-28
 */


//公告
@RestController
@RequestMapping("/notice")
@Api(value = "NoticeController", description = "公告表")
@CrossOrigin
public class NoticeController {

    @Autowired
    public NoticeService noticeService;

    @Autowired
    public NoticeUserService noticeUserService;
    @Autowired
    private UmsAdminService umsAdminService;


    @ApiOperation(value = "根据编号查询信息")
    @GetMapping("/getNotice")
    public Object getItem(@RequestParam("id") Long id) {
        Notice notice = noticeService.getById(id);
        return K.ok().data(notice);
    }

    //公告展示
    @ApiOperation(value = "前台展示接口")
    @GetMapping("/getListneed")
    public Object getListneed() {
        //获取当前用户信息
        UmsMember currentMember = umsAdminService.getCurrentMember();
        if (currentMember == null) {
            return K.error().message("用户不存在");
        }
        return noticeService.getListneed(currentMember);
    }

    //公告展示
    //传此信息的id
    @ApiOperation(value = "点击一个信息后此信息变为已读")
    @GetMapping("/reads")
    public Object reads(@RequestParam(value = "id") Long id) {
        //获取当前用户信息
        UmsMember currentMember = umsAdminService.getCurrentMember();
        if (currentMember == null) {
            return K.error().message("用户不存在");
        }
        return noticeService.reads(currentMember, id);
    }
    //公告展示
    @ApiOperation(value = "获取当前登录用户的未读数量")
    @GetMapping("/getnotread")
    public Object getnotread(){
        //获取当前用户信息
        UmsMember currentMember = umsAdminService.getCurrentMember();
        if(currentMember==null){
            return K.error().message("用户不存在");        }
        return noticeService.notread(currentMember);
    }
}